package org.example.base;

import lombok.Data;

/**
 * @author huangy
 * @description
 * @since 2022/11/9 19:47
 **/
@Data
public class BaseResp<T> {

    /**
     * 状态码
     */
    private int code;

    /**
     * 返回信息
     */
    private String message;

    /**
     * 返回数据
     */
    private T data;

    private BaseResp(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    private BaseResp(int code, String message) {
        this.code = code;
        this.message = message;
    }

    private BaseResp(int code) {
        this.code = code;
    }

    private BaseResp(String message) {
        this(BaseConstants.SUCCESS_CODE, message);
    }

    private BaseResp(T data) {
        this(BaseConstants.SUCCESS_CODE, BaseConstants.SUCCESS_MSG, data);
    }

    private BaseResp(String message, T data) {
        this(BaseConstants.SUCCESS_CODE, message, data);
    }

    public static <T> BaseResp<T> success() {
        return new BaseResp<>(BaseConstants.SUCCESS_MSG);
    }

    public static <T> BaseResp<T> success(String message) {
        return new BaseResp<>(message);
    }

    public static <T> BaseResp<T> success(T data) {
        return new BaseResp<>(data);
    }

    public static <T> BaseResp<T> success(String message, T data) {
        return new BaseResp<>(message, data);
    }

    public static <T> BaseResp<T> fail() {
        return new BaseResp<>(BaseConstants.FAIL_CODE, BaseConstants.FAIL_MSG);
    }

    public static <T> BaseResp<T> fail(String message) {
        return new BaseResp<>(BaseConstants.FAIL_CODE, message);
    }

}
